package atguigu06.polymorphism.exer3;

/**
 * ClassName: InstanceTest
 * Package: atguigu06.polymorphism.exer3
 * Description:
 *      建立InstanceTest 类，在类中定义方法method(Person e);
 *      在method中:
 *      (1)根据e的类型调用相应类的getInfo()方法。
 *       (2)根据e的类型执行：
 *      如果e为Person类的对象，输出：
 *       “a person”;
 *       如果e为Student类的对象，输出：
 *       “a student”
 *       “a person ”
 *       如果e为Graduate类的对象，输出：
 *      “a graduated student”
 *       “a student”
 *       “a person”
 * @Author BuTang
 * @Create 2023/3/8 12:18
 * @Version 1.0
 */
public class InstanceTest {
    public void method(Person e){
        if (e instanceof Graduate) {
            System.out.println("a graduated student");
        }
        if (e instanceof Student) {
            System.out.println("a student");

        }
        if (e instanceof Person) {
            System.out.println("a person");
        }
    }

    public static void main(String[] args) {
        InstanceTest test = new InstanceTest();
        test.method(new Graduate());
        System.out.println();
        test.method(new Student());
        System.out.println();
        test.method(new Person());
    }
}
